package com.school.campus.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

/**
 * 活动相关Redis配置类
 * 解决school-campus和school-framework模块循环依赖问题
 */
@Configuration
public class ActivityRedisConfig {

    @Autowired
    private RedisKeyExpirationListener redisKeyExpirationListener;

    /**
     * 配置Redis消息监听器容器
     * 用于监听Redis键过期事件
     */
    @Bean
    public RedisMessageListenerContainer activityRedisMessageListenerContainer(RedisConnectionFactory connectionFactory) {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        // 订阅键过期事件通道
        container.addMessageListener(redisKeyExpirationListener,
                new org.springframework.data.redis.listener.ChannelTopic("__keyevent@0__:expired"));
        return container;
    }
}